package org.hpm.common.constant.enums;

import cn.hutool.core.util.ObjectUtil;

import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

/**
 * 性别枚举
 *
 * @author: jacklin
 * @date:  2021-12-05 13:03
 */
public enum Sex {

    MAN(0, "男"),
    WOMAN(1, "女"),
    SECRET(2, "保密");

    public final Integer code;
    private final String value;

    Sex(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public static Sex parse(String code) {
        if (ObjectUtil.isNotNull(code)) {
            Optional<Sex> optional = Arrays.stream(values()).filter(e -> Objects.equals(e.getCode(), code)).findFirst();
            if (optional.isPresent()) {
                return optional.get();
            }
        }
        return null;
    }
}
